package com.ques.controller;

import com.ques.pojo.Question;
import com.ques.service.AnswerService;
import com.ques.service.QuestionService;
import com.ques.pojo.QuestionAnswer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author zq  2020-01-07
 */
@Controller
public class QuestionController {

    @Autowired
    private QuestionService questionService ;

    @Autowired
    private AnswerService answerService ;
    /**
     *  访问问卷
     * @param page 问卷的 id
     * @param model
     * @return 响应页面
     */
    @RequestMapping("/{page}.html")
    public String questionPage(@PathVariable("page") String page, Model model){
        model.addAttribute("name","nihao");
        System.out.println(page);
        Question question =  questionService.getQuestionById(page);

        model.addAttribute("question",question) ;
        return "index" ;
    }
    @RequestMapping("/submit")
    public String submitPage(String questionId,QuestionAnswer questionAnswer){

        System.out.println(questionAnswer);


        boolean bool = answerService.addQuestionAnswer(questionId,questionAnswer) ;
        if (bool) {
            return  "success" ;
        }else {
            return  "result" ;
        }
    }
}
